<template>
	<view class="m30">
		<view class="c343 bold">{{detail.name}}</view>
		<view class="c343 f28 mt20">{{detail.explain}}</view>
		<view class="bgFff p20 radius50 mt20 flex-jus" v-if="detail.appId">
			<text class="c343 f26">{{detail.linkText}}</text>
			<view class="flex" @click="openWxmini">
				<text class="f26 blue">去{{detail.appName}}</text>
				<u-icon name="arrow-right" color="#0066FD" size="14"></u-icon>
			</view>
		</view>
		<view class="mt20 mb30 c999 f26 textC">{{detail.guide}}</view>
		<view class="mt20 bgE0 c343 f28 p20 radius50">· 受理条件</view>
		<view class="mt20 ml30 mr30">
			<view class="f26 c343 mt20" v-for="(item,index) in detail.acceptanceObj" :key="index">{{index + 1}}. {{item.value}}</view>
		</view>
		<view class="mt20 bgE0 c343 f28 p20 radius50">· 申请材料</view>
		<view class="mt20 ml30 mr30">
			<view class="mt20 flex-jus" v-for="(item,index) in detail.applicationObj" :key="index">
				<text class="f26 c343 flex1 textoverflow">{{index + 1}}. {{item.value}}</text>
				<view class="">
					<u-button color="#E2EFFF" :customStyle="{'color':'#0066FD'}" shape="circle"
						@click="getFile(item)">预览文件</u-button>
				</view>
			</view>
		</view>
		<view class="mt20 bgE0 c343 f28 p20 radius50">· 办事流程</view>
		<view class="mt20">
			<u-steps current="1" direction="column" activeColor="#0066FD" dot>
				<u-steps-item :title="item.value" v-for="(item,index) in detail.handleObj" :key="index">
				</u-steps-item>
			</u-steps>
		</view>
	</view>
</template>

<script>
	import {
		getMatterinfo
	} from '@/common/api_things.js'
	export default {
		name: '',
		data() {
			return {
				id: '',
				title:'',
				detail:{}
			}
		},
		onLoad(option) {
			this.id = option.id
			this.title = option.name
			uni.setNavigationBarTitle({
				title: this.title
			})
			this.getMatterinfo()
		},
		methods: {
			async getMatterinfo() {
				uni.showLoading({
					mask: true
				})
				const res = await getMatterinfo({
					id: this.id
				})
				if (res.code == 200) {
					this.detail = res.data
				}
				uni.hideLoading()
			},
			openWxmini(){
				uni.navigateToMiniProgram({
					appId:this.detail.appId,
					path:this.detail.appLink || ''
				})
			},
			getFile(item) {
				let link = this.api_host + item.fileLink
				uni.getSystemInfo({
					success: (res) => {
						if (res.system.includes('iOS')) {
							uni.navigateTo({
								url: '/pages/webview/index?link=' + decodeURIComponent(link)
							})
						} else {
							const downloadTask = uni.downloadFile({
								url: link,
								success: (res) => {
									const path = res.tempFilePath;
									uni.openDocument({
										filePath: path,
										fileType: 'pdf',
										success: (res) => {
											// uni.navigateBack({
											// 	delta: 1
											// });
											uni.showToast({
												title: '打开成功',
												icon: 'none',
												duration: 2000
											});
										},
										fail: (err) => {
											console.log(err, 'err');
											uni.showToast({
												title: '打开文件失败',
												icon: 'none',
												duration: 2000
											});
										}
									});
								},
								fail: (err) => {
									console.log(err, 'err');
									uni.showToast({
										title: '下载文件失败',
										icon: 'none',
										duration: 2000
									});
								}
							});
							downloadTask.onProgressUpdate(function(res) {
								uni.showLoading({
									title: '正在打开：' + res.progress + '%',
									mask: true
								})
							})
							uni.hideLoading()
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F0F7FF;
	}
</style>